package org.mistfx.mvp.demo;

import javafx.application.Preloader;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

/**
 * Created on 2015/6/8.
 *
 * @author Misty
 */
public class MyPreloader extends Preloader {
    private Stage stage;

    @Override
    public void start(Stage primaryStage) throws Exception {
        primaryStage.setScene(new Scene(new StackPane(new Label("Loading")),
                200, 80));
        primaryStage.show();
        this.stage = primaryStage;
    }

    @Override
    public void handleProgressNotification(ProgressNotification info) {
//        System.out.println("progress " + info.getProgress());
        super.handleProgressNotification(info);
    }

    @Override
    public void handleStateChangeNotification(StateChangeNotification info) {
//        System.out.println("stateChange " + info.getType());
        super.handleStateChangeNotification(info);
    }

    @Override
    public void handleApplicationNotification(PreloaderNotification info) {
//        System.out.println("application " + info);
        super.handleApplicationNotification(info);
        if (info instanceof StartedPreloaderNotification) {
            stage.hide();
        }
    }

    @Override
    public boolean handleErrorNotification(ErrorNotification info) {
//        System.out.println("error " + info.getCause());
        return super.handleErrorNotification(info);
    }
}
